package org.hazelnuts.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class GlobalConfiguration {

    @Bean(destroyMethod = "close", name = "oracleJdbcDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.hikari")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

//    @Bean(destroyMethod = "close", name = "oracleJdbcDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.tomcat")
//    public DataSource getDataSource() {
//        return DataSourceBuilder.create().type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
//    }

//    @Bean(destroyMethod = "close", name = "oracleJdbcDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.dbcp2")
//    public DataSource getDataSource() {
//        return DataSourceBuilder.create().type(org.apache.commons.dbcp2.BasicDataSource.class).build();
//    }

//    @Bean(destroyMethod = "close", name = "oracleJdbcDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.c3p0")
//    public DataSource getDataSource() {
//        return DataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
//    }

//    @Bean(destroyMethod = "close", name = "oracleJdbcDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.druid")
//    public DataSource getDataSource() {
//        return DataSourceBuilder.create().type(com.alibaba.druid.pool.DruidDataSource.class).build();
//    }


    @Bean(name = "oracleJdbcTemplate")
    public JdbcTemplate getJdbcTemplate(@Autowired DataSource oracleJdbcDataSource) {
        return new JdbcTemplate(oracleJdbcDataSource);
    }
}
